# -*- coding:utf-8 -*-
from PyQt5.QtWidgets import *
from PyQt5.QtCore import *
from PyQt5.QtGui import *

class GlobalVariablePanel(QWidget):
    picPath = "./com/mat/rpa/views/workWindow/rightPanel/images/"
    def __init__(self, parent=None):
        super(GlobalVariablePanel, self).__init__(parent)
        self.parentPanel = parent
        #设置全局布局管理器
        self.entireLayout = QVBoxLayout()
        self.entireLayout.setContentsMargins(0,0,0,0)
        self.entireLayout.setSpacing(0)
        self.setLayout(self.entireLayout)
        #添加topPanel
        self.topPanel = QWidget()
        self.topPanelLayout = QHBoxLayout()
        self.topPanelLayout.setContentsMargins(0,0,0,0)
        self.topPanelLayout.setSpacing(0)
        self.hintLabel = QLabel()
        self.hintLabel.setText("全局变量")
        self.topPanelLayout.addWidget(self.hintLabel)
        self.topPanelLayout.addStretch(1) #添加弹簧
        ##添加stackedWidget
        self.stackedWidget = QStackedWidget()
        self.stackedWidget.setContentsMargins(0,0,0,0)
        self.topPanelLayout.addWidget(self.stackedWidget)
        self.topPanel.setLayout(self.topPanelLayout)
        ###添加搜索按钮和添加变量按钮面板
        self.firstPanel = QWidget()
        self.firstPanelLayout = QHBoxLayout()
        self.firstPanel.setLayout(self.firstPanelLayout)
        self.firstPanelLayout.setContentsMargins(0,0,0,0)
        self.firstPanelLayout.setSpacing(0)
        self.firstPanelLayout.addStretch(1)
        self.searchBtn = QPushButton()
        self.searchBtn.setIcon(QIcon(QPixmap(GlobalVariablePanel.picPath+"search.png")))
        self.firstPanelLayout.addWidget(self.searchBtn)
        self.addVariableBtn = QPushButton()
        self.addVariableBtn.setIcon(QIcon(QPixmap(GlobalVariablePanel.picPath+"addVariable.png")))
        self.firstPanelLayout.addWidget(self.addVariableBtn)
        self.stackedWidget.addWidget(self.firstPanel)
        self.stackedWidget.setCurrentIndex(0)
        ###添加搜索框面板
        self.secondPanel = QWidget()
        self.secondPanelLayout = QHBoxLayout()
        self.secondPanelLayout.setContentsMargins(0,0,0,0)
        self.secondPanelLayout.setSpacing(0)
        self.secondPanel.setLayout(self.secondPanelLayout)
        self.secondPanelLayout.addStretch(1)
        self.searchBox = QLineEdit()
        self.secondPanelLayout.addWidget(self.searchBox)
        self.closeSearchBtn = QPushButton()
        self.closeSearchBtn.setIcon(QIcon(QPixmap(GlobalVariablePanel.picPath+"closeSearch.png")))
        self.secondPanelLayout.addWidget(self.closeSearchBtn)
        self.stackedWidget.addWidget(self.secondPanel)
        self.entireLayout.addWidget(self.topPanel,0.5)
        #添加变量表格
        self.variableTableView = QTableView()
        self.variableTableView.horizontalHeader().setStretchLastSection(True)
        self.variableTableView.horizontalHeader().setSectionResizeMode(QHeaderView.Stretch)
        self.variableTableModel = QStandardItemModel()
        # 设置表格头
        self.tableTitle = ['变量名称', '类型']
        self.variableTableModel.setHorizontalHeaderLabels(self.tableTitle)
        # 表格设置模型
        self.variableTableView.setModel(self.variableTableModel)
        self.entireLayout.addWidget(self.variableTableView, 9.5)

    def insertItemToVariableTable(self, row, col, item):
        self.variableTableModel.setItem(row, col, item)

